/*
 * Copyright (C) 2011  John Lawrence thegordo.john at gmail.com
 * Licensed under GPLv3 or later. see http://www.gnu.org/copyleft/gpl.html
 */

package org.jklawrencefam.server.ldap;

import org.jklawrencefam.Util.LogFactory;
import org.jklawrencefam.server.Processor;

import javax.swing.text.DateFormatter;
import java.net.Socket;
import java.text.ParseException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * User: John Lawrence
 * Date: 7/13/11
 * Time: 8:56 PM
 */
public class LDAPProcessor extends Processor {
    private static Logger logger = LogFactory.getLogger(LDAPProcessor.class.getName());

    @Override
    public void run() {
        logger.fine(generateSocketLog(socket));
        // TODO: Figure out what is happening with the LDAP Protocol.

    }

    private String generateSocketLog(Socket socket) {
        if (logger.getLevel() == Level.FINE) {
            DateFormatter formatter = new DateFormatter();
            StringBuilder message = new StringBuilder();
            message.append("Received connection from ");
            message.append(socket.getInetAddress());
            try {
                message.append(" at ").append(formatter.valueToString(new Date()));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            return message.toString();
        }
        return null;
    }
}
